FIX: Avoid parsing connection string multiple times in auth path (#580)#590
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Entra ID auth handling path so the connection string is parsed only once. Connection._construct_connection_string now returns both the built string and the normalized parameter dict, which is then passed directly to the auth helpers; process_connection_string (and the duplicate auth parsing it contained) is removed.
Changes:
_construct_connection_stringreturns(conn_str, normalized_params);Connection.__init__reuses the parsed dict for auth handling instead of regex-checking and re-parsing the string.auth.pyis reworked to operate on dicts:process_auth_parametersandextract_auth_typetake a parsed dict,remove_sensitive_paramsfilters a dict via the new_SENSITIVE_KEYS, and_AUTH_TYPE_MAPcentralizes the auth value→short-name mapping.process_connection_stringis removed.- Tests updated to the new dict-based signatures; the obsolete
TestProcessConnectionString*suites and the empty/no-equals-sign edge cases are dropped in favor of dict-input edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| mssql_python/auth.py | Replaces string-list APIs with dict-based ones; removes process_connection_string; adds _SENSITIVE_KEYS and _AUTH_TYPE_MAP. |
| mssql_python/connection.py | Uses the parsed param dict for auth handling; switches _construct_connection_string to return a tuple and builds the sanitized string via _ConnectionStringBuilder. |
| tests/test_003_connection.py | Updates _construct_connection_string call sites to unpack the new tuple. |
| tests/test_008_auth.py | Migrates tests to dict-based APIs; removes process_connection_string tests and obsolete edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.7%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 76.1%
mssql_python.__init__.py: 77.3%
mssql_python.pybind.connection.connection.cpp: 77.5%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.logging.py: 85.5%
mssql_python.connection.py: 85.6%🔗 Quick Links
|
a18953c to
b476518
Compare
|
PR looks good to me, didnt find any critical issue. |
bewithgaurav
left a comment
There was a problem hiding this comment.
two things to address before merge, added both inline
… jahnvi/auth_conn_string_parsing
Work Item / Issue Reference
Summary
This pull request significantly refactors the authentication handling and connection string construction in the
mssql_pythonpackage. The main improvements include migrating from string-based to dictionary-based parameter handling, consolidating authentication logic, and simplifying sensitive parameter removal. These changes modernize the codebase, reduce redundant parsing, and make it easier to extend or maintain authentication features.Authentication and connection string processing improvements:
mssql_python/auth.py,mssql_python/connection.py).UID,PWD,Trusted_Connection, andAuthentication) by using a canonical set and dictionary operations, ensuring robust sanitization before ODBC handoff (mssql_python/auth.py,mssql_python/connection.py).API and codebase modernization:
Connection._construct_connection_stringto return both the constructed string and the normalized parameter dictionary, enabling downstream logic to avoid reparsing and to use normalized parameters directly (mssql_python/connection.py)._construct_connection_string, ensuring continued correctness and coverage (tests/test_003_connection.py).Cleanup and removal of legacy code:
mssql_python/auth.py,mssql_python/connection.py,tests/test_008_auth.py).Overall, these changes streamline authentication handling, reduce parsing complexity, and lay a stronger foundation for future enhancements.